<?php
!defined('P_W') && exit('Forbidden');

/**
 * @param 页面信息 $_page
 * @param 默认seo配置 $_definedSeo
 * @param 楼盘名称 $_fname
 * @param 闲置字段 $_types
 * @param 闲置字段 $_subject
 * @param 闲置 $_tags
 * @param 闲置 $_summary
 * @return array()
 */
function houseSeoSettings($_page = 'index', $_definedSeo = array(), $_fname = '', $_types = '', $_subject = '', $_tags = '', $_summary = '') {
	global $house_sitename, $house_seoset;
	/* 网站名称，板块名称，帖子名称，文章概要  */
	$_replace = array($house_sitename, $_fname, $_types, $_subject, $_tags, $_summary);
	/*获取SEO配置信息  自定义->后台定义->默认*/
	empty($_definedSeo['title']) && $_definedSeo['title'] = $house_seoset['title'][$_page];
	empty($_definedSeo['metaDescription']) && $_definedSeo['metaDescription'] = $house_seoset['metaDescription'][$_page];
	empty($_definedSeo['metaKeywords']) && $_definedSeo['metaKeywords'] = $house_seoset['metaKeywords'][$_page];
	return seoSettings($_definedSeo, $_replace);
}
function GP($params) {
		if (!S::isArray($params)) return array();
		S::gp($params);
		$tmp = array();
		foreach ($params as $param) {
			$tmp[] = getGlobal($param);
		}
		return $tmp;
}
function getGlobal($key) {
		return isset($GLOBALS[$key]) ? $GLOBALS[$key] : '';
	}
function HouseCommentManager() {
	global $windid,$SYSTEM;
	if (isGM($windid)) return true;
	if (isset($SYSTEM['house_comment']) && $SYSTEM['house_comment']) return true;
	return false;
}

function getPageCache($type, $addition,$hid=0) {
	require_once M_P . 'lib/pagecache.class.php';
	switch ($type) {
		case 'info' :
			require_once M_P . 'lib/model/pagecacheconfiginfo.class.php';
			$pageCacheConfig = new PW_PageCacheConfigInfo($addition);
			break;
		case 'list' :
			require_once M_P . 'lib/model/pagecacheconfiglist.class.php';
			$pageCacheConfig = new PW_PageCacheConfigList($addition);
			break;
		case 'price' :
			require_once M_P . 'lib/model/pagecacheconfigprice.class.php';
			$pageCacheConfig = new PW_PageCacheConfigPrice($addition,$hid);
			break;
		case 'other' :
			require_once M_P . 'lib/model/pagecacheconfigother.class.php';
			$pageCacheConfig = new PW_PageCacheConfigOther();
			break;
	}
	$pageCache = new PW_PageCache($pageCacheConfig);
	return $pageCache;
}

class House extends PW_BaseLoader {

	/**
	 * 类文件的加载入口
	 * 
	 * @param string $className 类的名称
	 * @param string $dir 目录：末尾不需要'/'
	 * @param boolean $isGetInstance 是否实例化
	 * @return mixed
	 */
	function loadClass($className, $dir = '', $isGetInstance = true) {
		return parent::_loadClass($className, 'mode/house/lib/' . parent::_formatDir($dir), $isGetInstance);
	}

	/**
	 * 加载db类
	 * @param $className
	 */
	function loadDB($dbName, $dir = '') {
		parent::_loadBaseDB();
		return House::loadClass($dbName . 'DB', parent::_formatDir($dir) . 'db');
	}
	/**
	 * 加载service类
	 */
	function loadService($dbName,$isGetInstance = true) {
		return House::loadClass($dbName,'service');
	}
	/**
	 * 加载module类
	 */
	function loadModule($dbName,$isGetInstance = true) {
		return House::loadClass($dbName,'module');
	}
}

class secondTemplate {
	
	var $dir;

	function secondTemplate() {
		$this->dir = M_P . 'template/second/';
	}

	function getpath($template, $EXT = 'htm') {
		$srcTpl = $this->dir . "$template.$EXT";
		$tarTpl = D_P . "data/tplcache/house_second_" . $template . '.' . $EXT;
		
		if (!file_exists($srcTpl)) return false;
		
		if (pwFilemtime($tarTpl) > pwFilemtime($srcTpl)) return $tarTpl;
		
		return modeTemplate($srcTpl, $tarTpl);
	}

	function getDefaultDir() {
		return $this->dir;
	}

	//static function
	function printEot($template, $EXT = 'htm') {
		static $uTemplate = null;
		isset($uTemplate) || $uTemplate = new template(new secondTemplate());
		return $uTemplate->printEot($template, $EXT);
	}
}
/**
 * 判断用户是否是经纪人
 * @param unknown_type $uid
 * @param int $ifactive 是否要判断此用户是否激活或者锁定
 */
function checkBroker($uid,$ifactive = 1) {
	static $result = array();
	if (isset($result[$uid])) return $result[$uid];
	$brokerService = House::loadService('brokerservice');
	$temp = $brokerService->getBroker($uid);
	$result[$uid] = $temp ? $ifactive ? $temp['ifactive'] ? true :false:true:false;
	return $result[$uid];
}

function initAttach($attachs) {
	$attach = '';
	if ($attachs) {
		foreach ($attachs as $key => $value) {
			$attach .= "'$key' : ['$value[name]', '$value[size]', '$value[path]', '$value[type]', '', '', '', '$value[descrip]'],";
		}
		$attach = rtrim($attach, ',');
	}
	return $attach;
}

function isSuper(){
	global $windid;
	return isGM($windid);
}

function isManager(){
	global $windid,$groupid;
	return (isGM($windid) || $groupid == 3);
}

function isSelf($uid){
	global $winduid;
	return $winduid && $winduid == $uid;
}

function houseManager($type = 'sale'){
	global $SYSTEM,$winduid;
	return $winduid && ($type == 'sale' && $SYSTEM['house_sale']) || ($type == 'hire' && $SYSTEM['house_hire']);
}

function isHouseManager($uid,$type = 'sale'){
	return isSuper() || houseManager($type);
}
?>